package com.itlong.Server.impl;

import com.itlong.Mapper.UserMapper;
import com.itlong.Pojo.User;
import com.itlong.Server.UserServer;
import com.itlong.Util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class UserServerImpl implements UserServer {

    @Autowired
    private UserMapper userMapper;

    public User getUserByName(String username) {
        User u = userMapper.getUserByName(username);
        return u;
    }

    public void addUser(String username, String password){
        int i = userMapper.addUser(username,password);
    }

    @Override
    public void update(User user) {

        user.setUpdateTime(LocalDateTime.now());

        userMapper.update(user);
    }

    @Override
    public void updatePic(String picUrl) {

        Map<String, Object> map = ThreadLocalUtil.get();
        int id = (int) map.get("id");

        userMapper.updatePic(picUrl,id);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String, Object> map = ThreadLocalUtil.get();
        int id = (int) map.get("id");

        userMapper.updatePwd(newPwd,id);
    }
}
